package symbal;

import java.util.ArrayList;

public class Symbal extends SymbalNode{
    private String name;
    private Vtype vtype;
    private Vtype returntype;
    private ArrayList<Vtype> attrtypes;
    private boolean consts;
    private int len1;
    private int len2;
    private String mipsName;

    public Symbal(String name, Vtype vtype) {
        this.name = name;
        this.vtype = vtype;
        this.returntype = null;
        this.attrtypes = new ArrayList<>();
        this.consts = false;
    }

    public Symbal(String name, Vtype vtype, Vtype returntype) {
        this.name = name;
        this.vtype = vtype;
        this.returntype = returntype;
        this.attrtypes = new ArrayList<>();
        this.consts = false;
    }

    public String getName() {
        return name;
    }

    public Vtype getVtype() {
        return vtype;
    }

    public Vtype getReturntype() {
        return returntype;
    }

    public boolean isConsts() {
        return consts;
    }

    public void setConsts() {
        consts = true;
    }

    public ArrayList<Vtype> getAttrtypes() {
        return attrtypes;
    }

    public void addAttr(Vtype attrtype) {
        attrtypes.add(attrtype);
    }

    public void setLen1(int len1) {
        this.len1 = len1;
    }

    public void setLen2(int len2) {
        this.len2 = len2;
    }

    public int getLen1() {
        return len1;
    }

    public int getLen2() {
        return len2;
    }

    public String getMipsName() {
        return mipsName;
    }

    public void setMipsName(String mipsName) {
        this.mipsName = mipsName;
    }

    public boolean checkAttrtypes(ArrayList<Vtype> attrtypes) {
        int len = attrtypes.size();
        int len1 = this.attrtypes.size();
        if (len != len1) {
            return false;
        }
        if (len == 0) {
            return true;
        }
        for (int i = 0; i < len; i++) {
            if (!attrtypes.get(i).equals(this.attrtypes.get(i))) {
                return false;
            }
        }
        return true;
    }

    public String toString() {
        String str = name;
        str += " ";
        str += vtype.toString();
        if (vtype.equals(Vtype.FUNC)) {
            str += " ";
            str += returntype.toString();
            str += " [";
            for (Vtype vt: attrtypes) {
                str += " ";
                str += vt.toString();
            }
            str += "]";
        }
        str += " " + mipsName;
        return str;
    }
}
